#ifndef __ARR2D_SIMPLE_HPP__
#define __ARR2D_SIMPLE_HPP__

#include <vector>

class Arr2d 
{
public:

  /// This is the default constructor. It doesn't do anything:
  Arr2d() :
    nrows(0), ncols(0)
  {
  }

  /// Create a 2D array that is nr by nc.
  Arr2d(int nr, int nc)
  {
    resize(nr, nc);
  }

  /// Create a 2D array that is given a default value:
  Arr2d(int nr, int nc, double val)
  {
    resize(nr, nc);
    setall(val);
  }

  /// Resize the array:
  void resize(int nr, int nc)
  {
    nrows = nr;
    ncols = nc;

    storage.resize(nrows);
    for(int i = 0; i < nrows; i++) {
      storage[i].resize(ncols);
    }    
  }

  /// Set all of the array elements to some value:
  void setall(double val)
  {
    int i, j;
    for(i = 0; i < nrows; i++) {
      for(j = 0; j < ncols; j++) {
	storage[i][j] = val;
      }
    }
  }

  /// Get an element of the array. By returning a reference, we can
  /// use this function to change the value:
  double& get(int r, int c)
  {
    return storage[r][c];
  }

  /// Get an elemnt of the array. This can be used for const arrays
  const double& get(int r, int c) const
  {
    return storage[r][c];
  }

private:

  /// The storage member stores all of our data:
  std::vector<std::vector<double> > storage;

  /// The number of rows:
  int nrows;

  /// The number of columns:
  int ncols;

};  // <-- Make sure that you include this semicolon

#endif
